home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / dos / doname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-13  |  2.1 KB  |  97 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: doname.c,v 1.2 1996/09/13 17:50:06 digulla Exp $
  4.     $Log: doname.c,v $
  5.     Revision 1.2  1996/09/13 17:50:06  digulla
  6.     Use IPTR
  7.  
  8.     Revision 1.1  1996/09/11 12:54:45  digulla
  9.     A couple of new DOS functions from M. Fleischer
  10.  
  11.     Desc:
  12.     Lang: english
  13. */
  14. #include <exec/memory.h>
  15. #include <clib/exec_protos.h>
  16. #include <dos/dosextens.h>
  17. #include <dos/filesystem.h>
  18. #include <clib/dos_protos.h>
  19. #include <clib/utility_protos.h>
  20. #include "dos_intern.h"
  21.  
  22. LONG DoName(struct IOFileSys *iofs, STRPTR name)
  23. {
  24.     extern struct DosLibrary *DOSBase;
  25.     STRPTR volname, pathname, s1;
  26.     BPTR cur;
  27.     struct DosList *dl;
  28.     struct Device *device;
  29.     struct Unit *unit;
  30.     struct FileHandle *fh;
  31.     struct Process *me=(struct Process *)FindTask(NULL);
  32.  
  33.     if(!Strnicmp(name,"PROGDIR:",8))
  34.     {
  35.     cur=me->pr_HomeDir;
  36.     volname=NULL;
  37.     pathname=name+8;
  38.     }else
  39.     {
  40.     /* Copy volume name */
  41.     cur=me->pr_CurrentDir;
  42.     s1=name;
  43.     pathname=name;
  44.     volname=NULL;
  45.     while(*s1)
  46.         if(*s1++==':')
  47.         {
  48.         volname=(STRPTR)AllocMem(s1-name,MEMF_ANY);
  49.         if(volname==NULL)
  50.             return me->pr_Result2=ERROR_NO_FREE_STORE;
  51.         CopyMem(name,volname,s1-name-1);
  52.         volname[s1-name-1]=0;
  53.         pathname=s1;
  54.         break;
  55.         }
  56.     }
  57.  
  58.     dl=LockDosList(LDF_ALL|LDF_READ);
  59.     if(volname!=NULL)
  60.     {
  61.     /* Find logical device */
  62.     dl=FindDosEntry(dl,volname,LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS);
  63.     if(dl==NULL)
  64.     {
  65.         UnLockDosList(LDF_ALL|LDF_READ);
  66.         FreeMem(volname,s1-name);
  67.         return me->pr_Result2=ERROR_DEVICE_NOT_MOUNTED;
  68.     }
  69.     device=dl->dol_Device;
  70.     unit  =dl->dol_Unit;
  71.     }else if(cur)
  72.     {
  73.     fh=(struct FileHandle *)BADDR(cur);
  74.     device=fh->fh_Device;
  75.     unit  =fh->fh_Unit;
  76.     }else
  77.     {
  78.     device=DOSBase->dl_NulHandler;
  79.     unit  =DOSBase->dl_NulLock;
  80.     }
  81.  
  82.     iofs->IOFS.io_Device =device;
  83.     iofs->IOFS.io_Unit     =unit;
  84.     iofs->io_Args[0]=(IPTR)pathname;
  85.  
  86.     /* Send the request. */
  87.     DoIO(&iofs->IOFS);
  88.  
  89.     if(dl!=NULL)
  90.     UnLockDosList(LDF_ALL|LDF_READ);
  91.  
  92.     if(volname!=NULL)
  93.     FreeMem(volname,s1-name);
  94.  
  95.     return me->pr_Result2=iofs->io_DosError;
  96. }
  97.